express = require('express')
app = express()
app.locals.moment = require('moment')
path = require('path')
mongoose = require('mongoose')
cookieParser = require('cookie-parser')
cookieSession = require('cookie-session')
bodyParser = require('body-parser')
methodOverride = require('method-override')
serveStatic = require('serve-static')
logger = require("morgan")
require 'iced-coffee-script/register'
multipart = require('connect-multiparty')
routes = require './config/routes'

port = process.env.PORT || 4000
dbUrl = 'mongodb://localhost:27017/imooc'

app.set 'views', path.join(__dirname, './app/views/pages')
app.set('view engine', 'jade')

app.use(bodyParser.urlencoded({extended: true}));
if 'development' is app.get('env')
  app.set('showStackError', true)
  app.use(logger(':method :url :status'))
  app.locals.pretty = true
  mongoose.set('debug', true)
app.use methodOverride('_method', methods: [
  'GET'
  'POST'
])
# #session会话 存储 实现登陆持久
app.use cookieParser()
app.use cookieSession(keys: [
  'k1'
  'k2'
])
app.use(multipart())

app.use(serveStatic(path.join(__dirname,'public')));
routes(app)
mongoose.connect(dbUrl)
app.listen(port)

